package vip.zhenzicheng;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhenzicheng
 * @DESCRIPTION: 统一异常处理
 * @DATE: 2022/04/24 5:18 PM
 */
public class ExceptionHandlerController {

  @ExceptionHandler
  @ResponseStatus(value = HttpStatus.BAD_REQUEST)
  @ResponseBody
  public Object exceptionHandler(RuntimeException e) {

    Map<String, Object> result = new HashMap<>();
    result.put("status", "error");
    result.put("message", e.getMessage());
    return result;
  }
}
